<?php

namespace app\api\controller\v1;

use app\api\validate\IdCollection;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\ThemeException;
use think\Controller;
use think\Exception;
use think\Request;
use app\api\model\Theme as ThemeModel;
class Theme extends Controller
{
    /**
     * @url /theme?ids=id1,id2,id3,...
     * @return 一组theme模型
     */
    public function getSimpleList($ids='')
    {
        //TODO
        (new IdCollection())->goCheck();

        $ids = explode(',',$ids);
        $result = ThemeModel::with(['topicImg','headImg'])
//            ->fetchSql()
            ->select($ids);
        if (!$result){
            throw new ThemeException();
        }

        return $result;
    }

    /**
     * @url /theme/:id
     *
     */
    public function getComplexOne($id){
        //TODO
        (new IDMustBePostiveInt())->goCheck();
        $result = ThemeModel::getThemeWithProducts($id);
        if (!$result){
            throw new ThemeException();
        }
        return $result;
    }
}
